<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户首页</title>
    {% load static %}
    <link rel="stylesheet" type="text/css" href="{% static 'css/user.css' %}">
    <script>
        function remove(book_title, book_id) {
            const select = confirm('是否继续删除:' + book_title);
            if (select === true) {
                window.location.href = '/blog/remove/' + book_id
            }
        }
    </script>
</head>
<body>
<h1>这里是首页 你好 {{ username }}</h1>
{# 退出登陆的方法 #}
<a href="{% url 'blog:logout' %}">退出登录</a><br>

{# 有个小bug点击无效 #}
<button onclick="window.location.href={% url 'blog:logout' %}">退出登录</button>
<br>

<form action="{% url 'blog:logout' %}" method="post">
    {% csrf_token %}
    <button type="submit">退出登录</button>
</form>
<button>
    <a href="/blog/add_books/">添加书籍</a>
</button>
<table>
    <tr>
        <th>书ID</th>
        <th>书名</th>
        <th>价格</th>
        <th>作者</th>
        <th>操作</th>
    </tr>
    {% for i in books %}
        <tr>
            <th>{{ i.id }}</th>
            <td>{{ i.title }}</td>
            <td>{{ i.price }}</td>
            <td>{{ i.Author.name }}</td>
            <td>
                <a href="/blog/update/{{ i.id }}">更新</a>
                <a id="{{ i }}" onclick="remove('{{ i.title }}','{{ i.id }}')" href="">删除</a>
            </td>
        </tr>
    {% endfor %}
</table>
</body>
</html>